var del_case_summ = new Array();
var del_case_detail = new Array();
/**
 * 勾选所有接口汇总
 */
function selectAllSums() {
	$("#checkAllSums").click(function() {
		var check = $(this).closest('table').children('tbody').children('tr').find('td:first > input');
		var theads = $(this).closest('table').children('tbody').find("tr.tr-expandable").find('th:first  input');
		var checkAll = $(this).closest('table').children('tbody').find('tr').find('td:first > input');
		if (this.checked == true) {
			theads.each(function() {
				this.checked = true;
			});
			checkAll.each(function() {
				this.checked = true;
			});
		} else {
			check.each(function() {
				this.checked = false;
			});
		}
	});
}
/**
 * 选择当前summary接口
 */
function selectCurrentSum() {
	$(".checksum").click(function() {
		if (this.checked == true) {
			var select = $(this);
			var thead =select.parent().parent().next('tr.tr-expandable').find("table.testdata_table thead").find('th:first  input');
			var checkAlldetail = select.parent().parent().next('tr.tr-expandable').find("table.testdata_table tbody tr").find('td:first > input');
			thead.each(function() {
				if (this.checked == false) {
					this.checked = true;
				}		
			});
			checkAlldetail.each(function() {
				if (this.checked == false) {
					this.checked = true;
				}		
			});
		}		
	});
}
/**
 * 添加接口自动化页面-添加统一参数
 */
function addparams() {
	var ele = $("#param_tb").find("tr:last-child");
//	if (ele.find("input.form-control").length == 12){
//		$("#param_tb").append("<tr></tr>");
//		ele = $("#param_tb").find("tr:last-child");
//	}
	if(ele.find("input.form-control").length > 0){
		ele.append("<td align=\"center\" style=\"width: 2%;float:left;\">|</td>");
	}
	ele.append("<td style=\"width: 8%;float:left;\"><input type=\"text\" class=\"form-control urlparam_key\"/></td><td align=\"center\" style=\"width: 1%;float:left;\">:</td><td style=\"width: 8%;float:left;\"><input type=\"text\" class=\"form-control urlparam_value\" dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\"/></td>" +
			"<td style=\"width: 1%;float:left;\" align=\"center\">" +
			"<a href=\"####\" onclick=\"deleteparam(this);\"><img border=\"0\" src=\"img/delete.gif\" width=\"100%\" height=\"100%\"></a>"+		
			"</td>");
}
/**
 * 添加接口自动化页面-删除某个统一参数
 * @param element
 * @returns {Boolean}
 */
function deleteparam(element) {
	var e = $(element).parent();
	var e2 =  e.prev();
	var e3 = e2.prev();
	var e4 = e3.prev();
	var e5 = e4.prev();
	e5.remove();
	e4.remove();
	e3.remove();
	e2.remove();
	if (e5.prop('outerHTML') == undefined) {
		e.next().remove();
	}
	e.remove();
	return false;
}
/**
 * 添加接口测试页面-添加一个接口场景
 */
function addrow() {
	$("#tbody").append("<tr><td align=\"center\"><input type=\"checkbox\" class=\"checkTestData\" onclick=\"javascript:singleCheckData(this);\"></td>" +
			"<td dragtype=\"interparam\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\"></td>"+
			"<td><input style=\"width:100%;\" type=\"text\"></td>"+
			"<td><input style=\"width:100%;\" type=\"text\"></td>"+
			"<td dragtype=\"assertfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\"></td>"+
			"<td><input style=\"width:100%;\" type=\"text\"></td>"+
			"<td><div class=\"smart-form\" role=\"form\"><section class=\"pull-left no-padding col selectLevel\" style=\"width: 100%;\"><label class=\"select\" style=\"width: 100%;\"><select class=\"input-sm\" style=\"width: 100%;\"><option value=\"1\" selected=\"selected\">1</option><option value=\"2\">2</option></select><i></i></label></section></div></td>"+
			"<td><input style=\"width:100%;\" type=\"text\"></td>"+
			"<td><div class=\"smart-form\" role=\"form\"><section class=\"pull-left no-padding col\" style=\"width: 100%;\"><label class=\"select\" style=\"width: 100%;\"><select class=\"input-sm\" style=\"width: 100%;\"><option value=\"0\" selected=\"selected\">是</option><option value=\"1\">否</option></select><i></i></label></section></div></td>"+
			"<td align=\"center\"><input style=\"width:100%;\" type=\"button\" value=\"运行\" onclick=\"debugTest(getCurrentCase(this));\"></td>"+
			"<td></td>"+
			"</tr>");
//	alert(window.parent.document.getElementById("right_main").getAttribute("name"));
	var height = $("body").height();
	window.parent.document.getElementById("right_main").height = height;
}
/**
 * 添加自定义接口-添加接口参数详情
 */
function addInterfacedetails() {
	$("#addInterface").append("<tr><td align=\"center\"><input type=\"checkbox\"></td><td class=\"not_Empty_td\" ondblclick=\"ShowElement1(this);\"></td><td class=\"not_Empty_td\" ondblclick=\"ShowElement1(this);\"></td><td class=\"not_Empty_td\" ondblclick=\"ShowElement1(this);\"></td><td ondblclick=\"ShowElement1(this);\"></td></tr>");
	showErr();
}
//function getParams(interfacename) {
//	var paramsdetails = "<table class=\"table table-striped table-bordered table-hover has-tickbox\" style=\"table-layout:fixed\">" +
//			"<thead><tr><th style=\"width:30%;text-align: center;\">参数名</th><th style=\"width:10%;text-align: center;\">必选</th><th style=\"width:10%;text-align: center;\">类型</th><th style=\"width:50%;text-align: center;\">说明</th></tr></thead>"+
//			"<tbody><tr>" +
//			"<td style=\"\"><a id=\"orgcodes\" dragtype=\"interparam\" class=\"btn btn-success\"  type=\"button\" draggable=\"true\" ondragstart=\"drag(event)\">orgcodes</a></td>"+
//			"<td style=\"\">y</td>"+
//			"<td style=\"\">Integer</td>"+
//			"<td style=\"\">部门编号,多个以','相隔</td>"+
//			"<tr>" +
//			"<td style=\"\"><a id=\"carnum\" dragtype=\"interparam\" class=\"btn btn-success\"  type=\"button\" draggable=\"true\" ondragstart=\"drag(event)\">carnum</a></td>"+
//			"<td style=\"\">y</td>"+
//			"<td style=\"\">String</td>"+
//			"<td style=\"\">部门编号,多个以','相隔SADAS撒的撒打算多撒多撒大所多撒大所大所大所多撒大声地撒撒大所多</td>"+
//			"</tr>"+
//			"</tr></tbody></table>";
//	$("#params").html(paramsdetails);
//}
/**
 * 允许拖拽触发方法
 */
function allowDrop2(ev) {
	var e = $(ev.target);
	var drageletype = dragele.attr("dragtype");
	if (e.attr("dragtype") == 'undefined' || e.attr("dragtype") == undefined) {
		var es = e.parents("*[dragtype]");
		if (es.length > 0) {
			e = es.eq(0);
		}
	}
	else {
		var es = e.parents("*[dragtype]");
		if (es.length > 0) {
			if (es.eq(0).attr("dragtype") == e.attr("dragtype")) {
				e = es.eq(0);
			}		
		}
	}
	if (e.attr("dragtype") == drageletype) {
		ev.preventDefault();
	}
}

var map = new Map();
/**
 * 拖拽后触发方法
 * @param ev
 */
function drop(ev) {
	ev.preventDefault();
	var data = ev.dataTransfer.getData("ID");
	var item = document.getElementById(data).cloneNode(true);
	var e = $(ev.target);
	//如果拖拽的元素没有定义拖拽类型就从其父元素查找判断拖拽类型
	if (e.attr("dragtype") == 'undefined' || e.attr("dragtype") == undefined) {
		e = e.parents("*[dragtype]");
	}
	else {
		var es = e.parents("*[dragtype]");
		if (es.attr("dragtype") == e.attr("dragtype")) {
			e = es;
		}		
	}
	//拖动接口参数
	if (e.attr("dragtype") == 'interparam') {
		var html = e.html();
		 if (isStrEmpt(html)){
			 e.append("<table style=\"width: 100%\"></table>");
		 }
		 var tr = e.find("table:last-child");
		 tr.append("<tr><td style=\"float:left;\">"+$(item).removeAttr("id").prop("outerHTML")+"</td><td align=\"center\" style=\"float:left;\">:</td><td style=\"width: 100px;float:left;\"><input type=\"text\" dragtype=\"paramsfuction\" class=\"form-control\"/></td>" +
				"<td style=\"width: 13px;float:left;\" align=\"center\">" +
				"<a href=\"####\" onclick=\"deleteInterparam(this);\" classname=\"\"><img border=\"0\" src=\"img/delete.gif\" width=\"100%\" height=\"100%\"></a>"+		
				"</td></tr>");
	}
	//取值函数
	else if (e.attr("dragtype") == 'paramsfuction'){
		var modalid = addmodal();
		var modalele = $("#"+modalid+"");
		map.set(modalid,e);		
		modalele.modal();
	}
	//断言函数
	else if (e.attr("dragtype") == 'assertfuction'){
		var modalid = addAssertModal();
		var modalele = $("#"+modalid+"");
		map.set(modalid,e);		
		modalele.modal();
	}
	
}

/**
 * 字体自动根据屏幕分辨率匹配大小
 */
function fixFontSize() {
	var maxHeight=40;       //固定高度 
	var maxWidth=60;        //固定宽度
	var height=[];
	var width=[];
	var button=$(".params");
	for(var i=0;i<button.length;i++){
		button[i].style.fontSize="8px";
		height[i]=button[i].offsetHeight;
		width[i]=button[i].offsetWidth;
		while(parseInt(height[i])<maxHeight&&parseInt(width[i])<maxWidth){    //逐次递增字体大小，使字体达到最大的字号
			button[i].style.fontSize=parseInt(button[i].style.fontSize)+1+"px";
			height[i]=button[i].offsetHeight;
			width[i]=button[i].offsetWidth;
		}
		button[i].style.width="60px";
		button[i].style.height="40px";
	}
}
/**
 * 获得取值函数
 * @returns {String}
 */
function getParamsFunction() {	
	var functionOptions;
	$.ajax({
		url : "/smarttest-frontstage/autog7/getParamsFunction.action",
		method : 'POST',
		async:false,
		error:function(response,error){
			functionOptions = "";
			dialog('error','error'+response.status,3000);
			}, 
		success : function(data) {
			functionOptions = data.data;
		}
	});
	return functionOptions;
}
/**
 * 获得断言函数
 * @returns {String}
 */
function getAssertFunction () {
	var functionOptions;
	$.ajax({
		url : "/smarttest-frontstage/autog7/getAssertFunction.action",
		method : 'POST',
		async:false,
		error:function(response,error){
			functionOptions = "";
			dialog('error','error'+response.status,3000);
			}, 
		success : function(data) {
			functionOptions = data.data;
		}
	});
	return functionOptions;
}
/**
 * 选择接口后根据接口名获得接口的参数，展示在web端
 * @param element
 */
function getFunctionParams(element) {	
	var parentcode = $(element).parent().parent().parent();
	var e =  parentcode.next().next();
	var selectfunc = $(element).find("option:selected").val();
	var params = "<table style=\"width: 60%\">";
	if (selectfunc!="") {
		var paramsstr = selectfunc.substring(selectfunc.indexOf('(')+1,selectfunc.indexOf(')'));
		if (!isStrEmpt(paramsstr)) {
			var paramsarr = paramsstr.split(',');
			for (var i = 0; i < paramsarr.length; i++) {
				params+="<tr><td style=\"float:left;\">"+paramsarr[i]+"</td><td align=\"center\" style=\"float:left;\">&nbsp;:&nbsp;</td><td style=\"width: 150px;float:left;\"><input type=\"text\" dragtype=\"paramsfuction\" class=\"form-control\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\"/></td></tr>";
			}
		}	
	}
	params+="</table>";
	e.html(params);
}
/**
 * 新建并弹出添加取值函数窗口
 * @returns {String}
 */
function addmodal() {
	var modalid = "myModal_"+new Date().getTime();
	var modalStr = "<div class=\"modal fade\" id=\""+modalid+"\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">"+
	    "<div class=\"modal-dialog\">"+
	        "<div class=\"modal-content\">"+
	            "<div class=\"modal-header\">"+
	                "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" onclick=\"delmodal('"+modalid+"');\"> ×</button>"+   
	                "<h4 class=\"modal-title\" id=\"myModalLabel\" langlanguage=\"internalSharing\">添加取值函数<a ondragstart=\"drag(event)\" draggable=\"true\" type=\"button\" class=\"btn btn-warning\" dragtype=\"paramsfuction\" id=\"paramFuc\">取值函数</a></h4></div>"+            
	            "<div class=\"modal-body\">"+
	            	"<div class=\"pull-left global-search-box2\">"+
					    "<section class=\"pull-left no-padding col\">"+
						"<label class=\"\">选择函数</label><label class=\"input\"><select class=\"input-sm\" onchange=\"getFunctionParams(this);\" style=\"width:100%;max-width: 200px;\">"+
//						"<option selected=\"selected\" value=\"\"></option>"+
//						"<option value=\"getNow()\">getNow()</option>"+
//						"<option value=\"getNow(String format)\">getNow(String format,String str)</option>"+
						getParamsFunction()+
						"</select></label></section></div>"+
					"<div class=\"row no-margin margin-top-10 margin-bottom-10\"> </div>"+
					"<div class=\"row param-function\"></div></div>"+    
                "<div class=\"modal-footer\">"+
                	"<input id=\"shareType\" type=\"hidden\">"+
					"<button type=\"submit\" class=\"btn btn-primary btn-sm\" onclick=\"addFunction(this);\" langlanguage=\"save_adas\">确认</button>"+
                    "<button type=\"submit\" class=\"btn btn-default\" data-dismiss=\"modal\" langlanguage=\"cancel\" onclick=\"delmodal('"+modalid+"');\">取消</button>"+
                "</div></div></div></div>";
	$("#widget-grid").append(modalStr);
	return modalid;
}
/**
 * 新建并弹出添加断言函数窗口
 * @returns {String}
 */
function addAssertModal() {
	var modalid = "myModal_"+new Date().getTime();
	var modalStr = "<div class=\"modal fade\" id=\""+modalid+"\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">"+
	    "<div class=\"modal-dialog\">"+
	        "<div class=\"modal-content\">"+
	            "<div class=\"modal-header\">"+
	                "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" onclick=\"delmodal('"+modalid+"');\"> ×</button>"+   
	                "<h4 class=\"modal-title\" id=\"myModalLabel\" langlanguage=\"internalSharing\">添加断言函数<a ondragstart=\"drag(event)\" draggable=\"true\" type=\"button\" class=\"btn btn-warning\" dragtype=\"paramsfuction\" id=\"paramFuc\">取值函数</a></h4></div>"+            
	            "<div class=\"modal-body\">"+
	            	"<div class=\"pull-left global-search-box2\">"+
					    "<section class=\"pull-left no-padding col\">"+
						"<label class=\"\">选择函数</label><label class=\"input\"><select class=\"input-sm\" onchange=\"getFunctionParams(this);\" style=\"width:100%;max-width: 200px;\">"+
//						"<option selected=\"selected\" value=\"\"></option>"+
//						"<option value=\"getNow()\">getNow()</option>"+
//						"<option value=\"getNow(String assert1,String assert2)\">getNow(String assert1,String assert2)</option>"+
						getAssertFunction()+
						"</select></label></section></div>"+
					"<div class=\"row no-margin margin-top-10 margin-bottom-10\"> </div>"+
					"<div class=\"row param-function\"></div></div>"+    
                "<div class=\"modal-footer\">"+
                	"<input id=\"shareType\" type=\"hidden\">"+
					"<button type=\"submit\" class=\"btn btn-primary btn-sm\" onclick=\"addAssertFunction(this);\" langlanguage=\"save_adas\">确认</button>"+
                    "<button type=\"submit\" class=\"btn btn-default\" data-dismiss=\"modal\" langlanguage=\"cancel\" onclick=\"delmodal('"+modalid+"');\">取消</button>"+
                "</div></div></div></div>";
	$("#widget-grid").append(modalStr);
	return modalid;
}
/**
 * 删除添加函数后的弹窗
 * @param modalid
 */
function delmodal(modalid) {
	$("#"+modalid+"").modal('hide');
	setTimeout(function(){
		$("#"+modalid+"").remove();
    },500);
}
/**
 * 添加取值函数
 * @param element
 */
function addFunction (element) {
	var e = $(element).parents(".modal").find("option:selected");
	var e2 = $(element).parents(".modal").find("td > input");
	var modalid = $(element).parents(".modal").attr('id');
	if (isStrEmpt(e.val())) {
		dialog('error', '请选择取值函数', 3000);
	}
	else {
		var func = e.val().split("(", 1)+"(";
		for (var i = 0; i < e2.length; i++) {
			if (i > 0) {
				func += ",";
			}
			func += e2.eq(i).val();
		}
		func+=")";
		delmodal(modalid);
		map.get(modalid).val(func);
	}
	
}
/**
 * 添加断言函数
 * @param element
 */
function addAssertFunction (element) {
	var e = $(element).parents(".modal").find("option:selected");
	var e2 = $(element).parents(".modal").find("td > input");
	var modalid = $(element).parents(".modal").attr('id');
	if (isStrEmpt(e.val())) {
		dialog('error','请选择断言函数',3000);
	}
	else {
		var func = e.val().split("(", 1)+"(";
		for (var i = 0; i < e2.length; i++) {
			if (i > 0) {
				func += ",";
			}
			var value = e2.eq(i).val();
			func += value;
		}
		func+=")";
		delmodal(modalid);
		map.get(modalid).append("<label onmousemove=\"mouseover(this);\" onmouseout=\"mouseout(this);\" style=\"margin-bottom:0px !important;\"><div style=\"float:left\"><a class=\"btn btn-info assert-details\" type=\"button\" classname=\""+e.attr("classname")+"\" style=\"margin-left: 5px\" >"+func+"</a></div><div style=\"float:left;width:20px;height:32px;display: none\" class=\"delassert\"><a href=\"####\" onclick=\"deleteassert(this);\">"+
		"<img width=\"15px\" height=\"15px\" border=\"0\" src=\"img/delete.gif\"></a></div></label>");
		showAssertDetails("showinfo2");
	}	
}
/**
 * 展现删除断言的按钮
 * @param e
 */
function mouseover(e) {
	$(e).find('div.delassert').show();
}
/**
 * 隐藏删除断言的按钮
 * @param e
 */
function mouseout(e) {
	$(e).find('div.delassert').hide();
}
/**
 * 删除断言
 * @param e
 */
function deleteassert(e){
	var e1 = $(e).parent().parent();
	e1.remove();
}
/**
 * 鼠标放上去事件:展示断言详情
 * @param infoid
 */
function showAssertDetails(infoid) {
	jQuery(".assert-details").hover(
		    function(e){
				    Mouse(e);
				    $("#"+infoid).text($(this).text());
				    $("#"+infoid).css({top:toppos,left:leftpos}).fadeIn(100);
		   		},
			function(){
		   			$("#"+infoid).hide();
			}
	)
}
/**
 * 展示提示信息
 * @param element
 */
function ShowElement1(element)
{
	ShowElement(element,$(".showinfo"),$("#addInterface"),validata_addParams);
}
/**
 * 添加自定义接口
 */
function addInterface() {
	var form = $("#Interface_Add").data('bootstrapValidator');
	form.validate();
	var datas;
	if (form.isValid() == false) {
		return;
	}
	else {
		var notept_td = $(".not_Empty_td:visible");
		if (notept_td.length > 0) {
			dialog('error','请正确填写所有单元格',3000);
			return;
		}
		else {
			var intername = $.trim($("#intername").val());
			if (isInterfaceExisting(intername)) {
				dialog('error','自定义接口已存在,如要修改，请联系管理员',3000);
			}
			else {
				var trs = $("#addInterface").find("tr");
				var params_json = "["
				for (var i = 0; i < trs.length; i++) {
					var tmpstr = "{";
					var tds = trs.eq(i).find("td");
					tmpstr += "\"name\":\""+tds.eq(1).text()+"\"";
					tmpstr += ",\"type\":\""+tds.eq(2).text()+"\"";
					tmpstr += ",\"required\":\""+tds.eq(3).text()+"\"";
					tmpstr += ",\"detail\":\""+tds.eq(4).text()+"\"}";
					if (params_json != "[") {
						params_json += ",";
					}
					params_json += tmpstr;
				}
				params_json += "]";
				//添加到数据库
				dialog('loading','','');
				$.ajax({
					url : "/smarttest-frontstage/autog7/addInterface.action",
					data : {intername:intername,params:params_json},
					method : 'POST',
					error:function(response,error){
						dialog('error','error'+response.status,3000);
						}, 
					success : function(data) {
						if (data.data <= 0) {
							dialog('error','数据插入异常',3000);
						}
						else {
							dialog('succ','添加成功',3000);
							if (initInfSelectBox() == 0) {
								$('#Interface_Add').data('bootstrapValidator').resetForm(true);
								$('#addInterface').empty();
								$("#myModal").modal('hide');
								$("#interface").val(intername);
								$("#interface option[defined='self']").filter(function(){return $(this).text() == intername;}).attr('selected','selected');
								$('#interface').trigger("change");
							}						
						}
					}
				});	
			}		
		}
	}		
}
/**
 * 添加的自定义接口名是否已存在
 * @param name
 * @returns {Boolean}
 */
function isInterfaceExisting(name) {
	var isExist = false;
	$.ajax({
		url : "/smarttest-frontstage/autog7/getExistingInterface.action",
		data : {intername:name},
		method : 'POST',
		async:false,
		error:function(response,error){
			dialog('error','error'+response.status,3000);
			}, 
		success : function(data) {
			if (data.data > 0) {
				isExist = true;
			}
		}
	});	
	return isExist;
}
/**
 * 选择测试数据
 * @param element
 */
function selectTestData(element){
	var e = $(element).parent();
	var height = e.height();
	var width = e.width();
	e.html("<select style=\"height:"+height+"px;width:"+width+"px;\"><option>testdata</option></select>");
}
/**
 * 加载debug测试结果
 * @param element
 */
function launchTestResult(element) {
	var $e = $(element);
	var e = $e.parent().parent().next();
	if (isContains($e.attr("class"),"up")) {
		e.hide();
		$e.removeClass("up");
	}
	else {
//		e.show();
		e.css("display","table-row");
		$e.addClass("up");
	}	
}
/**
 * 加载测试结果详情
 * @param tr
 * @param sumid
 */
function launchInterDetails(tr,sumid) {
	$.ajax({
		url : "/smarttest-frontstage/AutoInterface/launchInterDetails.action",
		data : { summaryId : sumid , levels : $("#tbody").attr("level")},
		method : 'POST',
		async:false,
		error:function(response,error){
			dialog('error','error'+response.status,3000);
			}, 
		success : function(data) {
			if (data.status == 200 && data.data) {
				var html = "<tr style=\"overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"13\"><div style=\"border:1px solid #000\"><div><div class=\"row padding-10\"><div class=\"col-xs-8 col-sm-8\"><div class=\"btn-group\"><a class=\"btn btn-default widget-section-link\" langlanguage=\"add_vehicle\" onclick=\"runManyDetailTests(this);\">批量执行</a></div></div></div></div><div style=\"\"><table  class=\"table table-striped table-bordered table-hover has-tickbox testdata_table\" style=\"table-layout:fixed\">"+
				 "<thead><tr><th class=\"sorting_disabled center\" tabindex=\"0\" rowspan=\"1\" colspan=\"1\" style=\"width: 2%;text-align: center; white-space: nowrap;\" aria-label=\"\"><label class=\"no-margin\"><input id=\"checkAll\" class=\"checkbox style-0 checkAll\" type=\"checkbox\" checked=\"checked\" name=\"checkbox style-0 \"><span style=\"margin-right: 0px;\"></span></label></th><th style=\"width: 25%;text-align: center;\"><label id=\"testparams\">接口入参</label></th><th style=\"width: 5%;text-align: center;\"><label id=\"expectcode\">预期code</label></th><th style=\"width: 10%;text-align: center;\"><label id=\"expectmessage\">预期message</label></th><th style=\"width: 30%;text-align: center;\">"+
				 "<label id=\"assertresult\">结果断言</label></th><th style=\"width: 5%;text-align: center;\"><label id=\"expectnum\">期望条数</label></th><th style=\"width: 5%;text-align: center;\"><label id=\"testlevel\">level</label></th><th style=\"width: 10%;text-align: center;\"><label id=\"testdetails\">描述</label></th><th style=\"width: 5%;text-align: center;\"><label>运行</label></th><th style=\"width: 3%;text-align: center;\"><label id=\"result\"></label></th></tr></thead><tbody>";	
				var details  = "";
				for(var i=0;i<data.data.length;i++){
						 var value = data.data[i];
						 var param = solveParamsStr(value.innerparams);
						 var assert = solveAssertsStr(value.resultasserts);
						 details+="<tr detailid=\""+value.id+"\"><td align=\"center\"><input type=\"checkbox\" checked=\"checked\" value="+value.id+"></td><td>"+ param +"</td><td>"+value.expectcode+"</td><td>"+value.expectmsg+"</td><td>"+ assert +
						 "</td><td>"+value.expectcount+"</td><td>"+value.level+"</td><td>"+value.description+"</td><td align=\"center\"><input type=\"button\" value=\"运行\" onclick=\"runCurrentDetailTest(this);\" style=\"width:100%;\"></td><td></td></tr>";
					}
					html += details+"</tbody></table></div></div></td></tr>";
					tr.after(html);
					showAssertDetails("showinfo1");
					tr.next(".tr-expandable").hide();
					selectAll();
			     }
			}
	    });
}
/**
 * 加载测试结果详情并且展开
 * @param element
 * @param running
 */
function launchInterDetailsAndShow(element,running) {
	var $e = $(element);
	var currentTr = $e.parent().parent();
	var e = currentTr.next(".tr-expandable");
	if (e.length == 1) {
		if (isContains($e.attr("class"),"up")) {
			if (!running) {
				e.hide();
				$e.removeClass("up");
			}	
		}
		else {
			e.css("display","table-row");
			$e.addClass("up");
		}		
	}
	else {
		var id = currentTr.find('td:first-child input').eq(0).attr('sumid');
		$.ajax({
			url : "/smarttest-frontstage/AutoInterface/launchInterDetails.action",
			data : { summaryId : id , levels : $("#tbody").attr("level")},
			method : 'POST',
			error:function(response,error){
				dialog('error','error'+response.status,3000);
				}, 
			success : function(data) {
				if (data.status == 200 && data.data) {
					var html = "<tr style=\"overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"13\"><div style=\"border:1px solid #000\"><div><div class=\"row padding-10\"><div class=\"col-xs-8 col-sm-8\"><div class=\"btn-group\"><a class=\"btn btn-default widget-section-link\" langlanguage=\"add_vehicle\" onclick=\"runManyDetailTests(this);\">批量执行</a></div></div></div></div><div style=\"\"><table  class=\"table table-striped table-bordered table-hover has-tickbox testdata_table\" style=\"table-layout:fixed\">"+
					 "<thead><tr><th class=\"sorting_disabled center\" tabindex=\"0\" rowspan=\"1\" colspan=\"1\" style=\"width: 2%;text-align: center; white-space: nowrap;\" aria-label=\"\"><label class=\"no-margin\"><input id=\"checkAll\" class=\"checkbox style-0 checkAll\" type=\"checkbox\" checked=\"checked\" name=\"checkbox style-0 \"><span style=\"margin-right: 0px;\"></span></label></th><th style=\"width: 25%;text-align: center;\"><label id=\"testparams\">接口入参</label></th><th style=\"width: 5%;text-align: center;\"><label id=\"expectcode\">预期code</label></th><th style=\"width: 10%;text-align: center;\"><label id=\"expectmessage\">预期message</label></th><th style=\"width: 34%;text-align: center;\">"+
					 "<label id=\"assertresult\">结果断言</label></th><th style=\"width: 5%;text-align: center;\"><label id=\"expectnum\">期望条数</label></th><th style=\"width: 3%;text-align: center;\"><label id=\"testlevel\">level</label></th><th style=\"width: 10%;text-align: center;\"><label id=\"testdetails\">描述</label></th><th style=\"width: 3%;text-align: center;\"><label>运行</label></th><th style=\"width: 3%;text-align: center;\"><label id=\"result\"></label></th></tr></thead><tbody>";	
					var details  = "";
					for(var i=0;i<data.data.length;i++){
						 var value = data.data[i];
						 var param = solveParamsStr(value.innerparams);
						 var assert = solveAssertsStr(value.resultasserts);
						 details+="<tr detailid=\""+value.id+"\"><td align=\"center\"><input type=\"checkbox\" checked=\"checked\" value="+value.id+"></td><td>"+ param +"</td><td>"+value.expectcode+"</td><td>"+value.expectmsg+"</td><td>"+ assert +
						 "</td><td>"+value.expectcount+"</td><td>"+value.level+"</td><td>"+value.description+"</td><td align=\"center\"><input type=\"button\" value=\"运行\" onclick=\"runCurrentDetailTest(this);\" style=\"width:100%;\"></td><td></td></tr>";
					}
					html += details+"</tbody></table></div></div></td></tr>";
					currentTr.after(html);
					showAssertDetails("showinfo1");
					$e.addClass("up");
					currentTr.next(".tr-expandable").css("display","table-row");
					selectAll();
			     }
			}
	    });		
	}	
}
/**
 * 获得bootstrapValidator 表单的数据
 * @param formname
 * @returns
 */
function getDatas (formname) {
	var form = $(formname).data('bootstrapValidator');
	form.validate();
	var datas;
	//如果数据校验不通过，不返回数据
	if (form.isValid() == false) return;
	var d = {};
    var t = $(formname).serializeArray();
    $.each(t, function() {
      d[this.name] = this.value;
    });
    datas = JSON.stringify(d);
    return datas;
}
/**
 * bootstrapValidator添加自定义接口，并验证数据
 */
function validata_addParams() {
	$("#addInterface").bootstrapValidator({
		message : 'This value is not valid',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			add_name : {
				message : '请输入参数名',
				validators : {
					notEmpty : {
						message : '不能为空'
					},
				}
			},
			add_necessary : {
				message : '请选择是否必选',
				validators : {
					notEmpty : {
						message : '不能为空'
					},
				}
			},
			add_type : {
				message : '请输入类型',
				validators : {
					notEmpty : {
						message : '不能为空'
					},
				}
			},
		}
	})
}
/**
 * 根据测试环境加载模块
 * @param element
 */
function LoadModuleByEnv(element){
	var $e = $(element);
	var selected = $e.val();
	$.ajax({
	url : "/smarttest-frontstage/AutoInterface/getModuleByEnv.action",
	data : { id : selected },
	method : 'POST',
	success : function(data) {
		if (data.status == 200 && data.data) {
			var html = "";
			for(var i=0;i<data.data.length;i++){
				 var value = data.data[i];
				 html += "<option value="+value.id+">"
					+ value.name
					+ "</option>"
			}
			$("#module_usefor").empty();
			$("#module_usefor").html(html);
			$('#module_usefor').selectpicker('refresh');
		    $('#module_usefor').selectpicker('render');
	     }
	}
	});
	$.ajax({
		url : "/smarttest-frontstage/AutoInterface/getInfByEnv.action",
		data : { id : selected },
		method : 'POST',
		success : function(data) {
			if (data.status == 200 && data.data) {
				var html = "";
				for(var i=0;i<data.data.length;i++){
					 var value = data.data[i];
					 html += "<option value="+value.id+">"
						+ value.name
						+ "</option>"
				}
				$("#inf_usefor").empty();
				$("#inf_usefor").html(html);
				$('#inf_usefor').selectpicker('refresh');
			    $('#inf_usefor').selectpicker('render');
		     }
		}
	 });
	
}

function searchSubmit1(){
	var infs = $("#inf_usefor").val();
	var importants = $("#importants_search").val();
	var owners = $("#owner_search").val();
	$.ajax({
		url : "/smarttest-frontstage/AutoInterface/getInfBySearch.action",
		data : { 
			     idStr : JSON.stringify(infs),
			     importantsStr : JSON.stringify(importants),
			     ownersStr : JSON.stringify(owners)
			   },
		method : 'POST',
		success : function(data) {
			if (data.status == 200 && data.data) {
				var html = "";
				for(var i=0;i<data.data.length;i++){
					 var value = data.data[i];
					 var lastruntime = value.lastruntime==null?"":new Date(parseInt(value.lastruntime)).Format("yyyy-MM-dd hh:mm:ss");
					 var lastresult = value.lastresult==null?"":value.lastresult;
					 html += "<tr sumid=\""+value.id+"\"><td><input type=\"checkbox\" value="+value.id+"></td><td><div class=\"btn-group\"><button class=\"btn btn-default btn-xs dropdown-toggle\" data-toggle=\"dropdown\"><i class=\"fa fa-pencil\"></i><i class=\"fa fa-caret-down\"></i></button><ul class=\"dropdown-menu\">"+
							 "<li><a onclick=\"EditCase('this')\" href=\"javascript:void(0);\">编辑</a></li>"+
							 "<li><a onclick=\"\" href=\"javascript:void(0);\">删除</a></li>"+
							 "</ul></div></td><td>"+value.name+"</td><td>"+value.degreeid+"</td><td>"+value.modulename+"</td><td>"+value.tester+"</td><td>"+value.envdetail+"</td><td>"+value.requesttype+"</td><td>"+lastruntime+"</td><td><font color=\"red\">"+lastresult+"</font></td><td><div></div><a class=\"table-expandable-arrow btn btn-sm\" style=\"margin:0 auto;margin-top: 5px;\" searchId="+value.id+" onclick=\"launchInterDetailsAndShow(this);\"></a></td><td><a class=\"btn btn-primary btn-sm\" langlanguage=\"query\" type=\"button\" onclick=\"runCurrentSumTest(this,-1);\">运行</a></td></tr>"
				}
				$("#tbody").empty();
				$("#tbody").html(html);
		    }else{
		    	$("#tbody").empty();
		    }
			convertDataTable();
		}
	 });
}
/**
 * 查询后的处理，刷新bootstarp table
 */
function searchSubmit(){
//	alert(1);
//	var infs = $("#inf_usefor").val();
//	var importants = $("#importants_search").val();
//	var owners = $("#owner_search").val();
//	data : { 
//	     "idStr" : JSON.stringify(infs),
//	     "importantsStr" : JSON.stringify(importants),
//	     "ownersStr" : JSON.stringify(owners)
//	};
//	   alert(infs);
//	   alert(importants);
//	   alert(owners);
//	   datatable.fnSettings().ajax.data = data;
	   datatable.ajax.reload( function ( json ) {
		    //这里的json返回的是服务器的数据
//		    $('#myInput').val( json.lastInput );
		    selectCurrentSum();
		} );   
	   //选择level后界面只展示该level的场景
	   var levels = $("#level_search").val();
	   if (isStrEmpt(levels)) {
		   $("#tbody").attr("level",""); 
	   }
	   else {
		   $("#tbody").attr("level",levels); 
	   }
	   del_case_summ = [];
	   del_case_detail = [];
}
var groupset = new Set();
/**
 * 批量运行接口测试
 * @param releaseid 版本id
 */
 function runSumTests(releaseid) {
		var selects = $("#dt_basic").find('tr[role="row"]').find('td:first input:checked');
		var map = new Map();
		var moduleids = "";
		var set = new Set();
		for (var i = 0; i < selects.length; i++) {
			var tr = selects.eq(i).parent().parent();
			var sumid = selects.eq(i).attr('sumid');
			map.set(tr,sumid);
			$.ajax({
				url : "/smarttest-frontstage/autog7/getModuleidBySumid.action",
				data : {sumid:sumid},
				method : 'POST',
				async:false,
				error:function(response,error){
					dialog('error','error'+response.status,3000);
					}, 
				success : function(data) {
					 if (!set.has(data.data)) {
						 if (moduleids != "") {
						    	moduleids+=",";
						  }
						 moduleids+=data.data;
						 set.add(data.data);
					 }
				}
			});
		}
		moduleids = "["+moduleids+"]";
		runManySumTests(releaseid,map,moduleids);
	}
 /**
  * 运行当前选中接口
  * @param element
  * @param releaseid
  */
	function runCurrentSumTest(element,releaseid) {
		var selects = $(element);
		var map = new Map();
		var moduleids = "";
		for (var i = 0; i < selects.length; i++) {
			var tr = selects.eq(i).parent().parent();
			var sumid = tr.find('td:first input').eq(0).attr('sumid');
			map.set(tr,sumid);
			$.ajax({
				url : "/smarttest-frontstage/autog7/getModuleidBySumid.action",
				data : {sumid:sumid},
				method : 'POST',
				async:false,
				error:function(response,error){
					dialog('error','error'+response.status,3000);
					}, 
				success : function(data) {
					if (moduleids != "") {
				    	moduleids+=",";
				    }
				 moduleids+=data.data;
				}
			});
		}
		moduleids = "["+moduleids+"]";
		runManySumTests(releaseid,map,moduleids);

	}
	/**
	 * 递归调用
	 * @param func
	 */
	 function fact(func) {
		 var t = func();
		 if (t == true) {
                fact(func);
          }
     } 
	 /**
	  * 运行批量接口测试的公共方法
	  * @param releaseid
	  * @param sumids
	  * @param moduleids
	  */
	function runManySumTests(releaseid,sumids,moduleids) {
//		$.ajax({
//			url : "/smarttest-frontstage/autog7/handleSetting.action",
//			data : {env:parseInt($("#index_usefor").val()),modules: moduleids},
//			method : 'POST',
//			error:function(response,error){
//				dialog('error','error'+response.status,3000);
//				}, 
//			success : function(data) {
				sumids.forEach(function (value,key,map) {
					$.ajax({
						url : "/smarttest-frontstage/autog7/getDatainitsBySumid.action",
						data : {sumid:value},
						method : 'GET',
						error:function(response,error){
							dialog('error','error'+response.status,3000);
							}, 
						success : function(data) {
							//判断数据初始化字段是否为空，为空就直接调用接口测试，不为空要走数据初始化流程，
							//根据模块，如果模块已经有数据在初始化，那么排队。
							if (data.data != '[]' && isStrEmpt(data.data)) {
//								var tmpbol = true;
								//采用递归的方式，等待有数据初始化的该组执行完毕
								fact(function () {
									if (!groupset.has(parseInt(value))) {
										groupset.add(parseInt(value));
										$.ajax({
											url : "/smarttest-frontstage/autog7/initData.action",
											data : {datainits:data.data},
											method : 'POST',
//											async:false,
											error:function(response,error){
												dialog('error','error'+response.status,3000);
												}, 
											success : function(returns) {
												groupset.delete(parseInt(value));
												if (key.next(".tr-expandable").length == 0) {
													launchInterDetails(key,value);
												}
												var resultdiv = key.find("td:nth-last-child(2) div");
												resultdiv.html("<img border=\"0\" src=\"img/msgbox_loading.gif\">");		
												var map = new Map();
												var e = key.next('tr.tr-expandable').find("table.testdata_table tbody tr").find('td:first input:checked');
												for (var i = 0; i < e.length; i++) {
													var tr = e.eq(i).closest("tr");
													map.set(tr,tr.attr("detailid"));
												};
												setTimeout(function(){
													$.ajax({
														url : "/smarttest-frontstage/autog7/insertSumResult.action",
														data : {sumid:value, releaseid: releaseid},
														method : 'POST',
														error:function(response,error){
															dialog('error','error'+response.status,3000);
															}, 
														success : function(data) {
															if (data.data > 0) {
																var sumresultid = data.data;
																var tmpint = runTest(map,sumresultid);
																var lastresult;
																if (tmpint == 0) {
																	resultdiv.html("<font color=\"red\">FAIL</font>");
																	lastresult = 1;
																}
																else if (tmpint%2 ==0) {
																	resultdiv.html("<font color=\"yellow\">SKIP</font>");
																	lastresult = 2;
																}
																else if (tmpint == 1) {
																	resultdiv.html("<font color=\"green\">PASS</font>");
																	lastresult = 0;
																}
																updateLastResult(value,sumresultid,lastresult);	
//																tmpbol = false;
																return false;
															}
														}
													});	
													
												},1);					
											}
										});
									}
									else {
										return true;
									}
								});
//								while(tmpbol) {
									
//								}
							}
							else {
								if (key.next(".tr-expandable").length == 0) {
									launchInterDetails(key,value);
								}
								var resultdiv = key.find("td:nth-last-child(2) div");
								resultdiv.html("<img border=\"0\" src=\"img/msgbox_loading.gif\">");		
								var map = new Map();
								var e = key.next('tr.tr-expandable').find("table.testdata_table tbody tr").find('td:first input:checked');
								for (var i = 0; i < e.length; i++) {
									var tr = e.eq(i).closest("tr");
									map.set(tr,tr.attr("detailid"));
								};
								setTimeout(function(){
									$.ajax({
										url : "/smarttest-frontstage/autog7/insertSumResult.action",
										data : {sumid:value, releaseid: releaseid},
										method : 'POST',
										error:function(response,error){
											dialog('error','error'+response.status,3000);
											}, 
										success : function(data) {
											if (data.data > 0) {
												var sumresultid = data.data;
												var tmpint = runTest(map,sumresultid);
												var lastresult;
												if (tmpint == 0) {
													resultdiv.html("<font color=\"red\">FAIL</font>");
													lastresult = 1;
												}
												else if (tmpint%2 ==0) {
													resultdiv.html("<font color=\"yellow\">SKIP</font>");
													lastresult = 2;
												}
												else if (tmpint == 1) {
													resultdiv.html("<font color=\"green\">PASS</font>");
													lastresult = 0;
												}
												updateLastResult(value,sumresultid,lastresult);	
											}
										}
									});	
									
								},1);
							}
						}
					});
							
				});
//			}
//		});
	}
	/**
	 * 更新上次执行结果写入数据库
	 * @param sumid
	 * @param sumresultid
	 * @param lastresult
	 */
	function updateLastResult(sumid,sumresultid,lastresult) {
		$.ajax({
			url : "/smarttest-frontstage/autog7/updateSumResult.action",
			data : {sumid:sumid, sumresultid:sumresultid, lastresult:lastresult},
			method : 'POST',
			error:function(response,error){
				dialog('error','error'+response.status,3000);
				}, 
			success : function(data) {
				if (data.data < 0) {
					dialog('error',"",3000);
				}
			}
		});	
	}
	/**
	 * 运行接口场景
	 * @param detailids
	 * @param sumresultid
	 */	
	function runTest(detailids,sumresultid) {
		var tmpint = 1;
		detailids.forEach(function (value,key,map) { 
			key.find("td:last").html("<img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/msgbox_loading.gif\">");
			$.ajax({
				url : "/smarttest-frontstage/autog7/runTest.action",
				data : {detailid:parseInt(value), sumresultid:sumresultid},
				method : 'POST',
				async:false,
				error:function(response,error){
					dialog('error','error'+response.status,3000);
					tmpint = 0;
					}, 
				success : function(data) {
					if (data.data.result == "PASS") {
						tmpint *= 1;
						key.find("td:last").html("<font color=\"green\">PASS</font>" +
								"<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
						if (isContains(key.next().attr('class'),'tr-expandable')) {
							key.next().remove();
						}
						key.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"+data.data.returns+"</p></td></tr>");
						launchTestResult(key.find("td:last a").get(0));
					}
					else if (data.data.result == "FAIL") {
						tmpint *= 0;
						key.find("td:last").html("<font color=\"red\">FAIL</font>" + 
								"<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
						if (isContains(key.next().attr('class'),'tr-expandable')) {
							key.next().remove();
						}
						key.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"+data.data.returns+"</p><p><font size=\"2\">错误详情&nbsp;&nbsp;:&nbsp;&nbsp;</font><font color=\"red\">"+data.data.errmsg+"</font></p></td></tr>");
						launchTestResult(key.find("td:last a").get(0));
					}
					else if (data.data.result == "SKIP") {
						tmpint *= 2;
						key.find("td:last").html("<font color=\"yellow\">SKIP</font>"+
								"<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
						if (isContains(key.next().attr('class'),'tr-expandable')) {
							key.next().remove();
						}
						key.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"+data.data.returns+"</p><p><font size=\"2\">错误详情&nbsp;&nbsp;:&nbsp;&nbsp;</font><font color=\"red\">"+data.data.errmsg+"</font></p></td></tr>");
						launchTestResult(key.find("td:last a").get(0));
					}
				}
			 });
		}); 
		return tmpint;
}
/**
 * 运行批量的接口场景
 * @param e
 */	
function runManyDetailTests(e) {
	var selects = $(e).parents('tr.tr-expandable').find("table.testdata_table tbody tr").find('td:first input:checked');
	var resultdiv = $(e).parents('tr.tr-expandable').prev().find("td:nth-last-child(2) div");
	var sumid = $(e).parents('tr.tr-expandable').prev().find('td:first input').eq(0).attr('sumid');
	var datamap = new Map();
	for (var i = 0; i < selects.length; i++) {
		var tr = selects.eq(i).parent().parent();
		datamap.set(tr,tr.attr('detailid'));
	}
	if (datamap.size > 0) {
		resultdiv.html("<img border=\"0\" src=\"img/msgbox_loading.gif\">");
		$.ajax({
			url : "/smarttest-frontstage/autog7/insertSumResult.action",
			data : {sumid:sumid, releaseid: -1},
			method : 'POST',
			error:function(response,error){
				dialog('error','error'+response.status,3000);
				}, 
			success : function(data) {
				if (data.data > 0) {
					var sumresultid = data.data;
					var tmpint = runTest(datamap,sumresultid);
					var lastresult;
					if (tmpint == 0) {
						resultdiv.html("<font color=\"red\">FAIL</font>");
						lastresult = 1;
					}
					else if (tmpint%2 ==0) {
						resultdiv.html("<font color=\"yellow\">SKIP</font>");
						lastresult = 2;
					}
					else if (tmpint == 1) {
						resultdiv.html("<font color=\"green\">PASS</font>");
						lastresult = 0;
					}
					updateLastResult(sumid,sumresultid,lastresult);	
				}
			}
		});	
	}	
} 
/**
 * 运行当前选中的接口场景
 * @param element
 */
function runCurrentDetailTest(element) {
	var selects = $(element);
	var resultdiv = selects.parents('tr.tr-expandable').prev().find("td:nth-last-child(2) div");
	var sumid = selects.parents('tr.tr-expandable').prev().find('td:first input').eq(0).attr('sumid');
	resultdiv.html("<img border=\"0\" src=\"img/msgbox_loading.gif\">");
	var map = new Map();
	for (var i = 0; i < selects.length; i++) {
		var tr = selects.eq(i).parent().parent();
		map.set(tr,tr.attr('detailid'));
	}
	$.ajax({
		url : "/smarttest-frontstage/autog7/insertSumResult.action",
		data : {sumid:sumid, releaseid: -1},
		method : 'POST',
		error:function(response,error){
			dialog('error','error'+response.status,3000);
			}, 
		success : function(data) {
			if (data.data > 0) {
				var sumresultid = data.data;
				var tmpint = runTest(map,sumresultid);
				var lastresult;
				if (tmpint == 0) {
					resultdiv.html("<font color=\"red\">FAIL</font>");
					lastresult = 1;
				}
				else if (tmpint%2 ==0) {
					resultdiv.html("<font color=\"yellow\">SKIP</font>");
					lastresult = 2;
				}
				else if (tmpint == 1) {
					resultdiv.html("<font color=\"green\">PASS</font>");
					lastresult = 0;
				}
				updateLastResult(sumid,sumresultid,lastresult);	
			}
		}
	});	
}
/**
 * 弹出添加定时任务的弹窗
 */
function alertAddTimerModal() {
	alert(123123123123);
	var selects = $("#dt_basic").find('tr[role="row"]').find('td:first input:checked');
	if (selects.length > 0) {
		$("#timertaskModal").modal();
	}
}

function solveParamsStr(element){
	var html ="<table style=\"width: 100%\"><tbody>";
	var ele = JSON.parse(element);
	for (key in ele){
		html+="<tr><td style=\"float:left;\"><a class=\"btn btn-success\" type=\"button\" >"+key+"</a></td><td align=\"center\" style=\"float:left;\">:</td><td style=\"float:left;\">" +
				"<a class=\"btn btn-default assert-details\" type=\"button\">"+ele[key]+"</a>";
//				"<input class=\"form-control assert-details\" type=\"text\" disabled=\"disabled\" value=\""++"\"></td></tr>";
	}
	html+="</tbody></table>";
	return html;
}

function solveAssertsStr(element){
	var html = ""; 
	if (!isStrEmpt(element)) {
		var ele = JSON.parse(element);
		for (key in ele){
			var assertstr = ele[key];
			var methodfullname = $.trim(assertstr.substring(0,assertstr.indexOf("(")));
			var paramstr = "("+$.trim(assertstr.substring(assertstr.indexOf("(")+1));
			var classname = methodfullname.substring(0,methodfullname.lastIndexOf("."));
			var assertMethod = methodfullname.substring(methodfullname.lastIndexOf(".")+1) + paramstr;
	       html+="<label><div style=\"float:left\"><a class=\"btn btn-info assert-details\" style=\"margin-left: 5px\" classname=\""+classname+"\" type=\"button\">"+assertMethod+"</a></div></label>";
		}
	}	
	return html;
}
var datatable;
/**
 * 加载接口自动化首页的table（bootstrap datatable）
 */
function convertDataTable () {
	datatable = $('#dt_basic').DataTable({
		 "dom": "<'row'<'col-md-6'l<'#toolbar'>><'col-md-6'f>r>" +
	        "t" +
	        "<'row'<'col-md-5 sm-center'i><'col-md-7 text-right sm-center'p>>",
       //是否查询框
       searching: true,
       //自动宽度
       "bAutoWidth":false,
//       //解决重新加载表格内容问题
       destroy:true,
       'bPaginate': true,
       "bRetrieve": true,
       //是否可排序
       "bSort": true,
       //有无进度条
       "bProcessing": true,
       "bStateSave": true,
       /*"serverSide": true,*/
       //ajax作为数据源
       "ajax": {
           "url": "/smarttest-frontstage/AutoInterface/getInfBySearch.action",
           "type": "POST",
           "data": function(){
        	   return {
        		   "env" : parseInt($("#index_usefor").val()),
        		   "modules" : JSON.stringify($("#module_usefor").val()),
        		   "idStr" : JSON.stringify($("#inf_usefor").val()),
      		     "importantsStr" : JSON.stringify($("#importants_search").val()),
      		     "ownersStr" : JSON.stringify($("#owner_search").val()),
      		   "levels" : JSON.stringify($("#level_search").val())
        	    }
           }
	},
	"aoColumnDefs": [{
        //设置第一列不排序
        "bSortable": false,
        "aTargets": [0],
    },
    {
        targets: 0,
        data: "id",
        render: function (data, type, row, meta) {
            return '<input type="checkbox" class="checksum" sumid="'+parseInt(data)+'">';
        }
    },
    {
        targets: 1,
        data: null,
        render: function (data, type, row, meta) {
            return '<div class="btn-group"><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"><i class="fa fa-pencil"></i><i class="fa fa-caret-down"></i></button><ul class="dropdown-menu"><li><a onclick="EditCase(this);"  href="javascript:void(0);">编辑</a></li><li class="divider"></li><li><a onclick=""  href="javascript:void(0);">删除</a></li></ul></div>';
        }
    },
    {
        targets: 3,
        data: "degreeid",
        render: function (data, type, row, meta) {
        	var degree;
        	if (data == 1) {
        		degree = "v1(高)";
        	}
        	else if (data == 2){
        		degree = "v2(中)";
        	}
        	else if (data == 3){
        		degree = "v3(低)";
        	}
            return degree;
        }
    },
    {
        targets: 8,
        data: "lastruntime",
        render: function (data, type, row, meta) {
     	   var lastruntime = data==null?"":new Date(parseInt(data)).Format("yyyy-MM-dd hh:mm:ss");
            return lastruntime;
        }
    },
    {
        targets: 9,
        data: "lastresult",
        render: function (data, type, row, meta) {
     	   var result;
     	   if (data == 1) {
     		   result = '<font color="red">FAIL</font>';
     	   }
     	   else if (data == 0){
     		   result = '<font color="green">PASS</font>'; 
     	   }
     	  else if (data == 2){
    		   result = '<font color="yellow">SKIP</font>'; 
    	   }
     	   else {
     		   result = ""; 
     	   }
            return result;
        }
    },
    {
        targets: 10,
        data:null,
        render: function (data, type, row, meta) {
            return '<div></div><a class="table-expandable-arrow btn btn-sm" style="margin:0 auto;margin-top: 5px;" onclick="launchInterDetailsAndShow(this,false);"></a>';
        }
    },
    {
        targets: 11,
        data: null,
        render: function (data, type, row, meta) {
            return '<a class="btn btn-primary btn-sm" langlanguage="query" type="button" onclick="runCurrentSumTest(this,-1);">运行</a>';
        }
    },
		],
		//列及参数设置
       "columns": [
            { "data": "id" },
			{ "data": null },
           { "data": "name" },
           { "data": "degreeid" },
           { "data": "modulename" },
           { "data": "tester" },
           { "data": "envdetail" },
           { "data": "requesttype" },
           { "data": "lastruntime" },
           { "data": "lastresult" },
           { "data": null },
           { "data": null }
       ],
       //初始化完成回调函数
       initComplete:function(){
           $("#toolbar").append('<div class="col-xs-8 col-sm-8"><div class="btn-group"><a href="addAutoCase.html" class="btn btn-default widget-section-link">新增</a><a  class="btn btn-default" onclick="delSelected($(\'#dt_basic\'));">删除</a></div><div class="btn-group"><a  class="btn btn-default" onclick="showReleaseModal();">批量执行</a><a  class="btn btn-default" onclick="alertAddTimerModal();">加入定时任务</a></div></div>');
           selectCurrentSum();
       },
       //"aaSorting": [[1, 'asc']],//排序
       "aLengthMenu": [[10, 20, 50, 100, -1], ['10', '20', '50','100', "所有"] // change per page values here
       ],
       "iDisplayLength": 10,
       "oLanguage": {
           "oAria": {
               "sSortAscending": " - click/return to sort ascending",
               "sSortDescending": " - click/return to sort descending"
           },
           "sProcessing": "玩命加载中...",
           "sLengthMenu": "显示 _MENU_ 记录",
           "sZeroRecords": "对不起，查询不到任何相关数据",
           "sEmptyTable": "未有相关数据",
           "sLoadingRecords": "正在加载数据-请等待...",
           "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录。",
           "sInfoEmpty": "当前显示0到0条，共0条记录",
           "sInfoFiltered": "（数据库中共为 _MAX_ 条记录）",
           "sSearch": "模糊查询：",
           "sUrl": "",
           //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
           "oPaginate": {
               "sFirst": "首页",
               "sPrevious": " 上一页 ",
               "sNext": " 下一页 ",
               "sLast": " 尾页 "
           }
       },
       //多语言配置

	});
}
/**
 * show 输入版本的弹窗
 */
function showReleaseModal() {
	var selects = $("#dt_basic").find('tr[role="row"]').find('td:first input:checked');
	if (selects.length > 0) {
		$('#releaseModal').modal();
	}
}
function singleCheckSummary(checkbox){
	var val = checkbox.getAttribute("sumid");
	if(checkbox.checked){
		if(-1==$.inArray(val, del_case_summ)){
			del_case_summ.push(val);
		}
	}else{
		var i = $.inArray(val, del_case_summ);
		if(i>-1){
			del_case_summ.splice(i, 1);
		}
	}
}

function singleCheckDetail(checkbox){
	var val = checkbox.value;
	if(checkbox.checked){
		if(-1==$.inArray(val, del_case_detail)){
			del_case_detail.push(val);
		}
	}else{
		var i = $.inArray(val, del_case_detail);
		if(i>-1){
			del_case_detail.splice(i, 1);
		}
	}
}


function EditCase(element) {
	var selects = $(element).parent().parent().parent().parent().parent().find("input[type=checkbox]").attr('sumid');
	if(selects<=0){
		dialog('error','请选择一条记录进行修改',3000);
	}else{
		$.cookie('updateAutoId',null);
		$.cookie('updateAutoId',selects);
		window.location.href="autog7update.html";
	}
}
/**
 * 运行接口时选择版本时的处理：0为迭代回归；1为普通运行		
 */
function handleRelease() {
	if($("#releasetype").find("option:selected").val() == 0) 
	{
		$('#releasename_section').show();
	} 
	else {
		$('#releasename_section').hide();
	}
}
/**
 * 添加定时任务时选择版本时的处理：0为迭代回归；1为普通运行
 */
function handleRelease2() {
	if($("#timer_releasetype").find("option:selected").val() == 0) 
	{
		$('#timer_releasename_section').show();
	} 
	else {
		$('#timer_releasename_section').hide();
	}
}